package com.ld.service;

import com.ld.dao.RoleDao;
import com.ld.dao.UserDao;
import com.ld.entity.Role;
import com.ld.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class MongoDBServiceImpl implements MongoDBService {
    @Autowired
    private UserDao userDao;

    @Autowired
    private RoleDao roleDao;

    @Transactional(rollbackFor = {Exception.class})
    public Boolean testTran() {
        User user1 = userDao.find(1l);
        user1.setAge(36);
        userDao.update(user1);

        Role role = new Role();
        role.setId(3l);
        role.setRoleName("hahaha");
        role.setRemark("dasdsadad");
        roleDao.insert(role);

        User user = new User();
        user.setId(2l);
        user.setAge(22);
        user.setUserName("qwerty");
        user.setOnline(false);
        userDao.insert(user);

        return null;
    }
}
